package cn.mju.tankfighterbackend

import cn.mju.tankfighterbackend.bean.AjaxResult
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap

fun <T> Result<T>.toAjaxResult(): AjaxResult<T> {
    return if (isSuccess) {
        AjaxResult.success(getOrNull())
    }else{
        AjaxResult.error("${exceptionOrNull()?.message}")
    }
}
fun <T,V> Result<T>.toAjaxResult(block:(T)->V): AjaxResult<V> {
    return if (isSuccess) {
        AjaxResult.success( getOrNull()?.let { block(it)})

    }else{

        AjaxResult.error("${exceptionOrNull()?.message}")
    }
}
fun <T,V> Result<T>.useToAjaxResult(  use:(T).()->V): AjaxResult<V> {
    return if (isSuccess) {
        AjaxResult.success(getOrNull()?.use())
    }else{
        AjaxResult.error("${exceptionOrNull()?.message}")
    }
}
fun <T>Boolean.toAjaxResult(): AjaxResult<T> {
    return if (this) {
        AjaxResult.success()
    }else{
        AjaxResult.error("")
    }
}
fun Boolean.onTrue(block:()->Unit): Boolean{
    if(this){
        block()
    }
   return this
}
fun Boolean.onFalse(block:()->Unit): Boolean{
    if(!this){
        block()
    }
   return this
}

